package co.th.bjc.md.dbonline.control;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import co.th.bjc.md.dbonline.bean.DepartmentDBOnlineBean;
import co.th.bjc.md.helper.DepartmentHelper;
import co.th.bjc.md.model.Department;

public class DepartmentDBOnlineControl {

	public List<DepartmentDBOnlineBean> findAllDepartment() {
		List<DepartmentDBOnlineBean> list = new ArrayList<DepartmentDBOnlineBean>(0);
		try {
			List<Department> listDepartment = new DepartmentHelper().findAllDepartment();
			for (Department department : listDepartment) {
				list.add(setModelToBean(department));
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return list;
	}
	
	private DepartmentDBOnlineBean setModelToBean(Department model){
		DepartmentDBOnlineBean bean = new DepartmentDBOnlineBean();
		bean.setDepartmentCode(model.getDepartmentCode().intValue());
		bean.setDepartmentNameTH(model.getDepartmentNameTH());
		bean.setDepartmentNameEN(model.getDepartmentNameEN());
		bean.setDepartmentDetail(model.getDepartmentDetail());
		return bean;
	}
	
	private Department setBeanToModel(DepartmentDBOnlineBean bean){
		Department model = new Department();
		model.setDepartmentCode(BigDecimal.valueOf(bean.getDepartmentCode()));
		model.setDepartmentNameEN(bean.getDepartmentNameEN());
		model.setDepartmentNameTH(bean.getDepartmentNameTH());
		model.setDepartmentDetail(bean.getDepartmentDetail());
		model.setExpertises(null);
		model.setCreateBy(null);
		model.setCreateDate(null);
		model.setUpdateBy(null);
		model.setUpdateDate(null);
		return model;
	}
}
